<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar bg-white shadow">
        <!--搜索框-->
        <div class="btn-group tool-button mt5">
            <el-input v-model="pageForm.groupName" @keyup.enter.native="doSearch" placeholder="群名"
                      size="medium"></el-input>
        </div>
        <!--搜索框-->
        <div class="btn-group tool-button mt5">
            <el-input v-model="pageForm.userKeyword" @keyup.enter.native="doSearch" placeholder="昵称或者用户名"
                      size="medium"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-date-picker
                    v-model="searchDate"
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    align="right"
                    size="medium"
                    :default-time="['00:00:00', '23:59:59']"
                    value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
        </div>
        <!--搜索条件-->
        <div class="btn-group tool-button mt5">
            <el-select v-model="pageForm.msgType" placeholder="请选择消息类型"
                       size="medium">
                <el-option
                        v-for="item in msgTypeData"
                        :key="item.val"
                        :label="item.name"
                        :value="item.val">
                </el-option>
            </el-select>
        </div>
        <!--搜索条件-->
        <div class="btn-group tool-button mt5">
            <el-select v-model="pageForm.oprType" placeholder="请选择记录类型"
                       size="medium">
                <el-option
                        v-for="item in oprTypeData"
                        :key="item.val"
                        :label="item.name"
                        :value="item.val">
                </el-option>
            </el-select>
        </div>
        <!--搜索按钮-->
        <div class="btn-group tool-button mt5">
            <el-button slot="append" icon="el-icon-search" @click="doSearch" size="medium"></el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                size="small"
                header-align="center"
                style="width: 100%">
            <el-table-column
                    label="群名"
                    prop="groupName"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <el-table-column
                    label="发送人昵称"
                    prop="nickname"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!---->
            <el-table-column
                    sortable
                    prop="username"
                    label="发送人用户名"
                    header-align="center"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="msgType"
                    label="消息类型"
                    header-align="center"
                    align="center">
                <template scope="scope">
                    <span>{{getMsgTypeName(scope.row.msgType)}}</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="msgOprType"
                    label="记录类型"
                    header-align="center"
                    align="center">
                <template scope="scope">
                    <span>{{getOprTypeName(scope.row.msgOprType)}}</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="msgContent"
                    label="内容"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    {{decodeURIComponent(scope.row.msgContent)}}
                </template>
            </el-table-column>
            <el-table-column
                    sortable
                    prop="ctAt"
                    label="时间"
                    header-align="center"
                    align="center">
                <template slot-scope="scope">
                    {{formatAt(scope.row.ctAt)}}
                </template>
            </el-table-column>
            <!--操作下拉菜单-->
            <el-table-column
                    label="操作"
                    width="120"
                    align="center">
                <template slot-scope="scope">
                    <el-button type="danger" size="mini" @click="del(scope.row.msgId)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </el-row>
    <!--分页容器-->
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>

</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            var self = this;
            return {
                pickerOptions: {
                    disabledDate: function (time) {
                        return time.getTime() > new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000);
                    },
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                searchDate: [],
                addDialogVisible: false,
                editDialogVisible: false,
                titlePopu: 0,
                tableData: [],
                msgTypeData: [],
                oprTypeData: [],
                pageForm: {
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    userType: "",
                    searchKeyword: "",
                    searchDate: "",
                },
                formData: {
                    nickname: "",
                    email: "",
                    anchor: "",
                    disabled: false,
                },
            }
        },
        methods: {
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm:ss");
                return "";
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                if (self.searchDate) {
                    self.pageForm.searchDate = self.searchDate.toString();
                } else {
                    self.pageForm.searchDate = "";
                }
                $.post(base + "/platform/user/group/record/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code === 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            del: function (id) {//删除
                let self = this;
                self.$confirm('此操作将删除这条记录，确定要删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    callback: function (a, b) {
                        if ("confirm" === a) {//确认后再执行
                            $.post(base + "/platform/user/group/record/del" , {id}, function (data) {
                                if (data.code === 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.pageData();
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        }
                    }
                });
            },
            getMsgTypeList: function () {
                let self = this;
                $.post(base + "/platform/chat/msg/typeList" , function (data) {
                    if (data.code === 0) {
                        self.msgTypeData = data.data;
                        self.msgTypeData.unshift({
                            name: '全部类型',
                            val: ''
                        });
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            getOprTypeList: function () {
                let self = this;
                $.post(base + "/platform/chat/msg/oprTypeList" , function (data) {
                    if (data.code === 0) {
                        self.oprTypeData = data.data;
                        self.oprTypeData.unshift({
                            name: '全部类型',
                            val: ''
                        });
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            getMsgTypeName:function(val){
                for (let msgTypeDataKey in this.msgTypeData) {
                    if (this.msgTypeData[msgTypeDataKey].val === val) {
                        return this.msgTypeData[msgTypeDataKey].name;
                    }
                }
            },
            getOprTypeName:function(val){
                for (let oprTypeDataKey in this.oprTypeData) {
                    if (this.oprTypeData[oprTypeDataKey].val === val) {
                        return this.oprTypeData[oprTypeDataKey].name;
                    }
                }
            }
        },
        created: function () {
            this.getMsgTypeList();
            this.getOprTypeList();
            this.pageData();
        }
    });
</script>

<!--#
}
#-->